package com.bkgy.modular.subjectQuery.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bkgy.modular.subjectQuery.entity.CalPdi2130;
import com.bkgy.modular.subjectQuery.entity.KeyValueEntity;
import com.bkgy.modular.subjectQuery.entity.ShareData;
import com.bkgy.modular.subjectQuery.mapper.CalPdi2130Mapper;
import com.bkgy.modular.subjectQuery.service.RightDataTabService;
import com.bkgy.sys.common.entity.ResultData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author ZhuHongKai
 * @version 1.0
 * @ClassName Cal
 * @date 2023/1/12 17:13
 */
@Service("cal_pdi")
public class CalPDI2130ServiceImpl implements RightDataTabService {
    @Resource
    private CalPdi2130Mapper calPdi2130Mapper;

    @Override
    public ResultData findByRightData(Integer pageIndex, Integer pageSize, String coilId, String hotId, ShareData shareData) {
        // 构建查询条件
        LambdaQueryWrapper<CalPdi2130> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CalPdi2130::getCust_mat_no,coilId);
        List<CalPdi2130> calPdi2130List = calPdi2130Mapper.selectList(queryWrapper);
        List<KeyValueEntity> list = new ArrayList<>();
        for (CalPdi2130 calPdi2130 : calPdi2130List) {
            Class c621Class = calPdi2130.getClass();
            Field[] declaredFields = c621Class.getDeclaredFields();
            for (int i = 0; i < declaredFields.length; i++) {
                Field field = declaredFields[i];
                field.setAccessible(true);
                KeyValueEntity keyValueEntity = new KeyValueEntity();
                keyValueEntity.setKey(field.getName());
                try {
                    keyValueEntity.setValue(field.get(calPdi2130));
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
                list.add(keyValueEntity);
            }
        }
        List<KeyValueEntity> entityList = list.stream().skip((pageIndex - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
        return ResultData.ResultDataSuccess(entityList, list.size());
    }
}
